/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package csm.uttils.encrypt;

/**
 *
 * @author Carlos S. Moreno <CarlosS.Moreno@gmail.com>
 */
public class Encrypt {

    public static enum encrypter {
        CESAR,
        TRANSPOSITION,
        VERNAM,
        VERNAM_MAUBORGNE,
        VIGENERE
    };

    private static CesarEncrypter cesar;
    private static TranspositionEncrypter transposition;
    private static VernamEncrypter vernam;
    private static VernamMauborgneEncrypter vernamM;
    private static VigenereEncrypter vigenere;

    private static Encrypter getEncrypter( encrypter arg)
    {
        switch(arg){
            default:
                System.out.println("No Encrypter specified, selecting Cesar's");
            case CESAR:
                if (null == cesar)
                    return cesar = new CesarEncrypter();
                else
                    return cesar;
            case TRANSPOSITION:
                if (null == transposition)
                    return transposition = new TranspositionEncrypter();
                else
                    return transposition;
            case VERNAM:
                if (null == vernam)
                    return vernam = new VernamEncrypter();
                else
                    return vernam;
            case VERNAM_MAUBORGNE:
                if (null == vernamM)
                    return vernamM = new VernamMauborgneEncrypter();
                else
                    return vernamM;
            case VIGENERE:
                if (null == vigenere)
                    return vigenere = new VigenereEncrypter();
                else
                    return vigenere;
        }
    }

    private static String getTextEncripted(String arg0, encrypter arg1)
    {
        Encrypter enc = getEncrypter(arg1);
        enc.setOpenMessage(arg0);
        return enc.getEncrypted();
    }

    public static String getEncryptedByCesar(String arg)
    {
        return getTextEncripted(arg, encrypter.CESAR);
    }

    public static String getEncryptedByTransposition (String arg)
    {
        return getTextEncripted(arg, encrypter.TRANSPOSITION);
    }

    public static String getEncryptedByVernam(String arg)
    {
        return getTextEncripted(arg, encrypter.VERNAM);
    }

    public static String getEncryptedByVernamMauborgne(String arg)
    {
        return getTextEncripted(arg, encrypter.VERNAM_MAUBORGNE);
    }

    public static String getEncryptedByVigenere(String arg)
    {
        return getTextEncripted(arg, encrypter.VIGENERE);
    }

}
